home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Software Vault: The Gold Collection
/
Software Vault - The Gold Collection (American Databankers) (1993).ISO
/
cdr35
/
tagdir.zip
/
TAGDIR.C
< prev
next >
Wrap
C/C++ Source or Header
|
1993-04-30
|
3KB
|
112 lines
/* $Header */
#include <windows.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#include "exports.h"
#include "startup.h"
#ifdef __BORLANDC__
LIBMAIN /* defines the LibMain() function for Borland C */
int DLL WEP(int nParam){return(1);}
#endif
void DLL
_init()
{
LibExport( "BOOL TagSetCWD BOOL");
LibExport( "BOOL tagDirHandler BOOL");
}
/* Public functions:
*
* This event handler is called whenever a file buffer becomes current.
* It determines the directory in which the newly current file is
* located and make Codewright's idea of the current tag file relative
* to that directory.
*
* Only the basename and extension of the tagfile, as specified in the
* TagSetFile command, will be used. Directory path information will
* be discarded.
*
* The purpose of this handler is to facilitate the use of Codewright
* for multiple projects. By default, Codewright assumes only one tag
* file per session. With this handler, the user need not bother about
* setting the tagfile name by hand when changing projects.
*/
BOOL DLL
TagSetCWD (BOOL turnon)
{
static HEVENT eHandle = NULL;
if (turnon)
{
if (eHandle = EventRegister (EVENT_BUFFER_CURRENT, EVENT_NORMAL,
"tagDirHandler"))
return(TRUE); // registration succeeded
else // registration failed
return(FALSE);
}
else if (eHandle)
{
if (!EventDeregister (eHandle)) // successfully deregistered
return(TRUE);
else // deregistration failed
return(FALSE);
}
}
/*
* The event handler. Returns TRUE if and only if it reset the
* tag file name.
*/
long DLL
tagDirHandler (long event, long data)
{
LPSTR fnam;
char filedir[_MAX_PATH] = "";
LPSTR drive, path, base, ext;
if (BufQIsSystem(BufQCurrentBuffer())) // ignore system buffers
return((long)FALSE);
if ((fnam = BufQFilename()) && *fnam)
{
if (!(fnam = StrNormalizePath(fnam))) // can't get file's directory
return((long)FALSE);
if (!StrSplitpath(fnam, &drive, &path, NULL, NULL))
return((long)FALSE);
strcat(filedir, drive);
strcat(filedir, ":");
strcat(filedir, path);
StrFree(drive);
StrFree(path);
StrFree(fnam);
}
if ((fnam = (LPSTR)LibFunctionExec("TagQFile")) && *fnam) // reuse fnam
{
if (!(fnam = StrNormalizePath(fnam)))
return((long)FALSE);
if (!StrSplitpath(fnam, NULL, NULL, &base, &ext))
return((long)FALSE);
if (filedir[strlen(filedir)-1] != '\\')
strcat(filedir, "\\");
strcat(filedir, base);
strcat(filedir, ext);
StrFree(base);
StrFree(ext);
TagSetFile(filedir);
StrFree(fnam);
return((long)TRUE);
}
return((long)FALSE);
}